package com.lingxu.module.message.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingxu.base.common.api.vo.Result;
import com.lingxu.module.message.entity.UserMessage;
import com.lingxu.module.message.mapper.MessageMapper;
import com.lingxu.module.message.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Title: MessageServiceImpl
 * @Package: com.lingxu.module.message.service.impl
 * @Author: ysj闫世杰
 * @Email: 1105324813@qq.com
 * @Date: Created in 2023/8/28 9:29
 * @Description:
 * @Version: 1.0.0
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, UserMessage> implements MessageService  {

    @Autowired
    private MessageMapper messageMapper;


    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * @Author ysj闫世杰
     * @Description 查询未读消息
     * @Date 2023/8/28 9:44
     * @Param: userId
     * @return com.lingxu.base.common.api.vo.Result
     **/
    @Override
    public Result findUnReadMessage(String userId) {
        try {
            List<UserMessage> data = messageMapper.findUnReadMessage(userId);
            return Result.ok(data,"查询成功");
        }catch (Exception e){
            logger.error("数据查询异常",e);
            return Result.error("查询异常");
        }
    }


    /**
     * @Author ysj闫世杰
     * @Description 消息已读
     * @Date 2023/8/28 14:13
     * @Param: ids
     * @return com.lingxu.base.common.api.vo.Result
     **/
    @Override
    public Result updateRead(List<String> ids) {
        try {
            messageMapper.updateRead(ids);
            return Result.ok("操作成功");
        }catch (Exception e){
            logger.error("操作异常",e);
            return Result.error("操作异常");
        }
    }
}
